package com.han.http.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @fileName: Print
 * @author: Han
 * @date: 2018/5/29 17:26
 * @dscription: 打印
 */
public class Print {

    /**
     * 打印map
     *
     * @param map 打印对象
     */
    public static void printMap(Map<String, List<String>> map) {

        Set<String> keySet = map.keySet();
        p("", 0);
        for (String key : keySet) {
            List<String> value = map.get(key);
            for (String string : value) {
                System.out.println(key + ":" + string);
            }
        }
    }

    public static void printlnInfo(Object msg) {
        p(msg, 0);
    }

    public static void printlnErr(Object msg) {
        p(msg, 1);
    }

    public static void printlnWarning(Object msg) {
        p(msg, 2);
    }

    private static void p(Object msg, int a) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yy-MM-dd HH:mm:ss");
        Date date = new Date(System.currentTimeMillis());
        String dateStr = simpleDateFormat.format(date);
        if (a == 0) {
            System.out.println("[INFO]" + dateStr + " " + msg);
        } else if (a == 1) {
            System.out.println("[ERROR]" + dateStr + " " + msg);
        } else if (a == 2) {
            System.out.println("[WARNING]" + dateStr + " " + msg);
        }
    }
}
